﻿//JumbotCms_4.1 Final
using System;
using System.Data;
using System.Web;
using Jumbot.Common;
namespace JumbotCms.Extends.Digg
{
    public partial class _ajax : JumbotCms.API.AdminCenter
    {
        private string _operType = string.Empty;
        private string _response = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {
            Server.ScriptTimeout = 8;//脚本过期时间
            this._operType = q("oper");
            switch (this._operType)
            {
                case "ajaxPluginDigg":
                    GetDigg();
                    break;
                case "ajaxPluginDiggCount":
                    GetDiggCount();
                    break;
                case "ajaxPluginDiggAdd":
                    GetDiggAdd();
                    break;
                default:
                    DefaultResponse();
                    break;
            }

            Response.Write(this._response);
        }

        private void DefaultResponse()
        {
            this._response = "{result :\"未知操作\"}";
        }
        private void GetDigg()
        {
            this._response = "{channeltype :\"" + q("cType") + "\",contentid:" + q("id") + "}";
        }
        private void GetDiggCount()
        {
            doh.Reset();
            doh.ConditionExpress = "contentid=" + q("id") + " and channeltype='" + q("cType") + "'";
            if (!doh.Exist("jcms_extends_digg"))
            {
                doh.Reset();
                doh.AddFieldItem("ContentId", q("id"));
                doh.AddFieldItem("ChannelType", q("cType"));
                doh.AddFieldItem("DiggNum", 0);
                doh.Insert("jcms_extends_digg");
            }
            doh.Reset();
            doh.ConditionExpress = "contentid=" + q("id") + " and channeltype='" + q("cType") + "'";
            this._response = "{count :\"" + Validator.IntStr(doh.GetValue("jcms_extends_digg", "DiggNum").ToString()) + "\"}";
        }
        private void GetDiggAdd()
        {
            string ChannelType = q("cType");
            if (!Jumbot.Common.Validator.IsNumeric(q("id")))//ID有误
            {
                this._response = "{count :\"0\", msg:\"ID有误\"}";
                return;
            }
            if (Jumbot.Common.Cookie.GetValue(q("cType") + "DiggNum" + q("id")) == null)
            {
                doh.Reset();
                doh.ConditionExpress = "contentid=" + q("id") + " and channeltype='" + q("cType") + "'";
                if (!doh.Exist("jcms_extends_digg"))
                {
                    doh.Reset();
                    doh.AddFieldItem("ContentId", q("id"));
                    doh.AddFieldItem("ChannelType", q("cType"));
                    doh.AddFieldItem("DiggNum", 0);
                    doh.Insert("jcms_extends_digg");
                }
                doh.Reset();
                doh.ConditionExpress = "contentid=" + q("id") + " and channeltype='" + q("cType") + "'";
                doh.Add("jcms_extends_digg", "DiggNum");
                Jumbot.Common.Cookie.SetObj(q("cType") + "DiggNum" + q("id"), "ok");
            }
            doh.Reset();
            doh.ConditionExpress = "contentid=" + q("id") + " and channeltype='" + q("cType") + "'";
            this._response = "{count :\"" + Validator.IntStr(doh.GetValue("jcms_extends_digg", "DiggNum").ToString()) + "\"}";
        }
    }
}
